home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD7459752000.psc / Mech VB.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-07-05  |  7.4 KB  |  186 lines

  1. VERSION 5.00
  2. Begin VB.Form Mech 
  3.    Appearance      =   0  'Flat
  4.    AutoRedraw      =   -1  'True
  5.    BackColor       =   &H00000000&
  6.    BorderStyle     =   0  'None
  7.    Caption         =   "Form1"
  8.    ClientHeight    =   12960
  9.    ClientLeft      =   0
  10.    ClientTop       =   0
  11.    ClientWidth     =   17280
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   12960
  16.    ScaleWidth      =   17280
  17.    ShowInTaskbar   =   0   'False
  18.    StartUpPosition =   3  'Windows Default
  19.    WindowState     =   2  'Maximized
  20.    Begin VB.Timer Timer1 
  21.       Interval        =   100
  22.       Left            =   8040
  23.       Top             =   6240
  24.    End
  25.    Begin VB.PictureBox Blank 
  26.       Appearance      =   0  'Flat
  27.       BackColor       =   &H80000005&
  28.       BorderStyle     =   0  'None
  29.       ForeColor       =   &H80000008&
  30.       Height          =   255
  31.       Left            =   360
  32.       ScaleHeight     =   255
  33.       ScaleWidth      =   255
  34.       TabIndex        =   0
  35.       Top             =   -300
  36.       Width           =   255
  37.    End
  38. Attribute VB_Name = "Mech"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Private Sub Form_Load()
  44.     Pie = 3.14159265358979
  45.     AngInc = 45
  46.     Ang = 0
  47.     'While statements make sure bitmap loads every time, with the exception
  48.     'of not enough memory.
  49.     While Mech1 = 0
  50.         Mech1 = GenerateDC(App.Path & "\Tank3.bmp")
  51.     Wend
  52.     While Mech2 = 0
  53.         Mech2 = GenerateDC(App.Path & "\TankW2.bmp")
  54.     Wend
  55.     While MechShootB = 0
  56.         MechShootB = GenerateDC(App.Path & "\Tankshoot2.bmp")
  57.     Wend
  58.     While MechShootW = 0
  59.         MechShootW = GenerateDC(App.Path & "\TankShootW.bmp")
  60.     Wend
  61. End Sub
  62. Public Function Game()
  63. 'Make sure AutoRedraw is set to True
  64.     Do
  65.         'This is neccesary, I'm not sure why.
  66.         Mech.Refresh
  67.         
  68.         'This command clears everything that is not an object on the
  69.         'form.  Basically it's an eraser. Try commenting it out, it
  70.         'is a pretty neat effect. If you are blitting a background
  71.         'comment this line out
  72.         Mech.Cls
  73.         
  74.         'This checks the state of the key in the ( ).  If it is pressed
  75.         'the variable that is set equal to the function will have a
  76.         'value of -32767 or less. If it isn't, it will have a value of 0
  77.         'You can also use KeyDown in place of this function, just make
  78.         'sure to include the DoEvents command in the loop.
  79.         
  80.         'IF THE KEYS RE BEING READ TOO FAST, which on most of the faster
  81.         'machines will be a problem, remove the < signs in on the "If"
  82.         'statements checking the key variables. Ex. "If Up = -32767 Then"
  83.         
  84.         Up = GetAsyncKeyState(vbKeyUp)
  85.         Down = GetAsyncKeyState(vbKeyDown)
  86.         Lef = GetAsyncKeyState(vbKeyLeft)
  87.         Rig = GetAsyncKeyState(vbKeyRight)
  88.         Shoot = GetAsyncKeyState(vbKeyControl)
  89.         En = GetAsyncKeyState(vbKeyEscape)
  90.          
  91.         
  92.         If Up <= -32767 Then
  93.             'This increments your speed forward, with a max of 3
  94.             If speed < 4 Then speed = speed + 1
  95.         End If
  96.         
  97.         If Down <= -32767 Then
  98.             'This increments your speed backwards with a min of -3
  99.             If speed > -4 Then speed = speed - 1
  100.         End If
  101.         
  102.         If Lef <= -32767 Then
  103.             'This increments the angle at which your traveling
  104.             Ang = Ang - AngInc
  105.             'This increments the position on the bitmap where you are going
  106.             'to blit from(In pixels). If you don't understand blitting look
  107.             'at the bitmap, it might help.
  108.             MechP = MechP - 102
  109.             'Once you have reached the beginning of the bitmap, this sets you
  110.             'at the end.
  111.             If MechP < 0 Then MechP = 714
  112.         End If
  113.         
  114.         If Rig <= -32767 Then
  115.             'This increments the angle at which your traveling
  116.             Ang = Ang + AngInc
  117.             'This increments the position on the bitmap where you are going
  118.             'to blit from(In pixels). If you don't understand blitting look
  119.             'at the bitmap, it might help.
  120.             MechP = MechP + 102
  121.             'Once you have reached the end of the bitmap, this starts you
  122.             'at the beginning again.
  123.             If MechP > 714 Then MechP = 0
  124.         End If
  125.         
  126.         If Shoot <= -32767 Then
  127.             'This switches the DC variables that are going to be blitted to
  128.             'the picture of the tank firing.  Once the loop has gone through
  129.             'and shoot does not = -32767, the else statement will switch it
  130.             'back to the normal tank picture. If you want you can put in a
  131.             'little timer to make the shoot picture last longer.
  132.             MechB = MechShootB
  133.             MechW = MechShootW
  134.             'Once you understand the motion part, this isn't too confusing
  135.             'I just made it so you move in the opposite direction of which
  136.             'your firing, in other words, recoil.  The "5 - speed" part
  137.             'makes it so there is less recoil at highr speeds
  138.             MechX = MechX - Cos(Ang / 180 * Pie) * (5 - speed)
  139.             MechY = MechY - Sin(Ang / 180 * Pie) * (5 - speed)
  140.         Else
  141.             MechB = Mech1
  142.             MechW = Mech2
  143.         End If
  144.         If En = -32767 Then
  145.             'You must delete and DC's you created, otherwise you
  146.             'will have memory loss
  147.              DeleteGeneratedDC Mech1
  148.              DeleteGeneratedDC Mech2
  149.              DeleteGeneratedDC MechB
  150.              DeleteGeneratedDC MechW
  151.              DeleteGeneratedDC MechShootB
  152.              DeleteGeneratedDC MechShootW
  153.             End
  154.         End If
  155.         'Just in case you are doing a lot of turning, this will prevent
  156.         'an overflow on the Ang variable.  For all you trig drop outs,
  157.         '360 and -360 degrees are = to 0 degrees.
  158.         If Ang = 360 Or Ang = -360 Then Ang = 0
  159.         
  160.         'This might seem confusing but it's not.  All I am doing is taking
  161.         'the Sin and Cos of the angle at which your pointing to figure out
  162.         'how far to move you in the X and Y coordinates.  The "/ 180 * Pie"
  163.         'part is just converting from degrees to radians.  The "* speed"
  164.         'part multiplies the answer by a number to make you go faster or
  165.         'slower in that direction.
  166.         MechX = MechX + Cos(Ang / 180 * Pie) * speed
  167.         MechY = MechY + Sin(Ang / 180 * Pie) * speed
  168.         
  169.         'If you have a background you want to use, you can use this line
  170.         'of code. Simply generate a DC like the others using the variable
  171.         'BackGround and uncommenting this line. If you use this, make sure
  172.         'you comment out the Mech.cls line.
  173.         'BitBlt Mech.hdc, 0, 0, Mech.ScaleWidth, Mech.ScaleHeight, BackGround, 0, 0, vbSrcCopy
  174.         
  175.         BitBlt Mech.hdc, MechX, MechY, 102, 72, MechW, MechP, 0, vbSrcAnd
  176.         BitBlt Mech.hdc, MechX, MechY, 102, 72, MechB, MechP, 0, vbSrcPaint
  177.     Loop
  178. End Function
  179. Private Sub Timer1_Timer()
  180.     Game
  181.     'I call the function in a timer because the form needs time to load.
  182.     'If you call it straight from form load, the form will not show unless
  183.     'you use both form.refresh and form.show in the loop.  I use the Timer
  184.     'because I think it make the program run faster.
  185. End Sub
  186.